import { defineStore } from "pinia";
import { ref } from "vue";

// 使用案例——注意，这种使用方法如果要持久化只能有一个变量,如果想在同事持久化存储多个参数，请参考下面“地震公共的变量——持久化版”
export const usePopStore = defineStore(
  "popStore",
  () => {
    const popName = ref<string>("");
    const setPopName = (name: string) => {
      popName.value = name;
    };
    return { popName, setPopName };
  },
  {
    // 持久化开启——
    persist: true,
  } as any
);

// 公共的变量——持久化版
export const useCommPersistenceStore = defineStore("commPersistenceStore", {
  state: () => ({
    mapType: "3D",
  }),
  actions: {
    setMapType(name: "3D" | "2D") {
      this.mapType = name;
    },
  },
  persist: true as any,
});
